dojo.provide("dojoscratch.AbstractCommand");

dojo.declare("dojoscratch.AbstractCommand", null, {
	constructor: function(boardElement) {
		console.debug("creating abstract command");
		//helping in calculating offset
		console.debug(boardElement);
		this._boardElement = boardElement;
		this._init();
		console.debug("abstract command inited");
	},
	_command: function() { 
		// to be overridden
	},	
	_init: function() {
		this._x1 = 0;
		this._y1 = 0;
		this._x2 = 0;
		this._y2 = 0;
		this._started = false;
	},
	start: function(x, y) {
		this._x1 = x - this._boardElement.offsetLeft;
		this._y1 = y - this._boardElement.offsetTop;
		this._started = true;
	},
	doing: function(x, y) {
		// Default implementation is intentionally left empty.
	},
	end: function(x, y) {
		if(this._started) {
			this._x2 = x - this._boardElement.offsetLeft;
			this._y2 = y - this._boardElement.offsetTop;
			this._command();
			this._init();
		}
	},
	_createScratch: function(shape, fill, stroke) {
		dojo.publish("scratchCreate", [shape, fill, stroke]);
	}
});